<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="./../../template/tagedu.xhtml">

    <ui:define name="title">
        <title><h:outputText value="Preencher Termo de Consentimento - TAG"/></title>
        <h:outputScript name="bigManage.js" library="js"/>
    </ui:define>

    <ui:define name="content">
        <h:form id="selectionF">
            <p:messages id="message" autoUpdate="true" showDetail="true"/>
            <h:outputText styleClass="enrollmentName" value="Preencher Termo de Consentimento"/>
            <h:panelGroup id="hbTerm">
                <div class="input-list">
                <h:outputLabel styleClass="label" for="consentCampaign" value="Campanha: "/>
                <p:selectOneMenu id="consentCampaign" value="#{consentTermBean.campaign}" label="Turma Preencher" converter="campaignC">
                    <f:selectItem value="#{null}" itemLabel="Selecione uma campanha:"/>
                    <f:selectItems value="#{consentTermBean.campaignList}"  var="c" itemLabel="#{c.name}" itemValue="#{c}" />    
                     <p:ajax update="consentUnity" process="@this"/>
                </p:selectOneMenu><br/>
                </div>
                <div class="input-list">
                <h:outputLabel styleClass="label" value="Ano: "/>
                <p:spinner value="#{consentTermBean.year}" min="#{consentTermBean.actualYear-1}" max="#{consentTermBean.actualYear}" size="4">
                    <f:validator validatorId="yearV"/>
                    <f:attribute name="minimo" value="#{(consentTermBean.actualYear-1).toString()}"/>
                    <f:attribute name="maximo" value="#{(consentTermBean.actualYear).toString()}"/>
                    <p:ajax update="consentUnity" process="@this consentCampaign"/>
                </p:spinner>
                </div>
                <div class="input-list">
                <h:outputLabel styleClass="label" for="consentUnity" value="Turma: "/>
                <p:selectOneMenu id="consentUnity" value="#{consentTermBean.unity}" converter="unityC">
                    <f:selectItem value="#{null}" itemLabel="Selecione uma unidade:"/>
                    <f:selectItems value="#{consentTermBean.unityList}" var="u" itemLabel="#{u.name}" itemValue="#{u}"/><br/>
                       <p:ajax update=":patientF" process="@this" listener="#{consentTermBean.loadDataTable()}"/>
                </p:selectOneMenu>
                </div>
                <div class="clear"></div>
                <br />
            </h:panelGroup>
        </h:form>
        
        <h:form id="patientF">
            <p:dataTable id="dataTableAlunos" var="patient" value="#{consentTermBean.aceptation}"
                         emptyMessage="Não existem alunos cadastrados nesta unidade ou nesta campanha">  
                <f:facet name="header">Alunos</f:facet>

                <p:column headerText="Nome">
                    <h:outputText value="#{patient.element.name}"/>
                </p:column>

                <p:column headerText="Coleta do HB foi autorizada?">
                    <center>
                        <p:selectOneButton value="#{patient.status}" onchange="setEdited(this);" converter="booleanC">
                            <f:selectItem itemLabel="Sim" itemValue="true" itemEscaped="false"/>
                            <f:selectItem itemLabel="Não" itemValue="false" itemEscaped="false"/>
                        </p:selectOneButton>
                        <h:inputHidden value="#{patient.edited}"/>
                    </center>
                </p:column>
            </p:dataTable>
            <div class="buttonGroup">
                <p:commandButton value="Salvar" action="#{consentTermBean.saveHB()}"
                                 disabled="#{consentTermBean.unity == null}"/>

                <p:commandButton action="#{consentTermBean.print()}" immediate="true"
                                 value="Imprimir" ajax="false" disabled="#{consentTermBean.unity == null}"
                                 onclick="this.form.target='_blank';"/>
            </div>
        </h:form>
    </ui:define>
</ui:composition>